using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    
    public partial class LinkStudentCourseComponent
    {

        /// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public List<LinkStudentCourse> SelectAllWDivision(int divisionId, string sortExpression)
        {
            List<LinkStudentCourse> listLinkStudentCourse = new List<LinkStudentCourse>();
            PlacementManager.DAL.LinkStudentCourse_DAL o = new PlacementManager.DAL.LinkStudentCourse_DAL();
            DataSet ds = o.SelectAllWDivisionId(divisionId);
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listLinkStudentCourse.Add(new LinkStudentCourse((int)row["StudentCourseId"], (string)row["UserName"], (int)row["CourseId"], (bool)row["IsCurrentlyEnrolled"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }
            if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }
            listLinkStudentCourse.Sort(new LinkStudentCourseComparer(sortExpression));
            return listLinkStudentCourse;
        }

        /// <summary>
        /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
        /// </summary>
        /// <returns>Boolean</returns>
        [DataObjectMethodAttribute(DataObjectMethodType.Update, false)]
        public bool UpdateEnrolledCourse(string UserName, int CourseId, string UpdatedBy)
        {
            PlacementManager.DAL.LinkStudentCourse_DAL oLinkStudentCourse = new PlacementManager.DAL.LinkStudentCourse_DAL();

            oLinkStudentCourse.UserName = UserName;
            oLinkStudentCourse.CourseId = CourseId;
            oLinkStudentCourse.UpdatedBy = UpdatedBy;

            return oLinkStudentCourse.UpdateEnrolledCourse();
        }
	}
}
